var http = require('http');
var querystring = require('querystring');

var gold = {
    "header" : {},
    "data" : {

        //游戏机会是否等于0
        "chance" : {
            "isZero" : false,
            "times" : '3'
        },

        // 每次夹到的分数是否合法
        "perScore": {
            "isrange" : true
        },

        //总分
        "totalScore" : {
            "isrange" : true
        },

        //券
        "quan" : {
            "level1" : "20",
            "level2" : "100",
            "level3" : "200",
            "level4" : "200"
        }
    }   
}

 
http.createServer(function (req, res) {

    var body = "";
    req.on('data', function (chunk) {
       body += chunk;
    });
    req.on('end', function () {
        // 解析参数
        body = querystring.parse(body);
        // 设置响应头部信息及编码
        res.writeHead(200, {
            'Content-Type': 'application/json',
            "access-control-allow-origin": "*",
            "access-control-allow-methods": "GET, POST",
            "access-control-allow-headers": "content-type, accept"
        });
        console.log(body);

        // var isrange = isNaN(body.score)?false:true;
        // // console.log(isrange);
        // if (isrange) {
            res.write(JSON.stringify(gold , null , 4));
        // }else{
        //     res
        // }
        res.end();
    });
    
}).listen(3007);
